library(tidyverse)
library(readxl)
library(fixest)
library(sjPlot)

### SET YOUR WORKING DIRECTORY TO THE FILE WHERE DATA IS STORED

################################### Load data  #################################################

bill_data = read_xlsx("bill_data.xlsx")

descriptive_data = read_xlsx('descriptive_data.xlsx')

bill_attr_data = read_xlsx("bill_attr_data.xlsx")

bill_attr_year_data = read_xlsx("bill_attr_year_data.xlsx")

bill_attr_state_data = read_xlsx("bill_attr_state_data.xlsx")

bill_attr_type_data = read_xlsx("bill_attr_type_data.xlsx")

open_states_all_votes = read_xlsx('open_states_all_votes.xlsx')

open_states_all_votes_state = read_xlsx('open_states_all_votes_state.xlsx')

open_states_contested_votes = read_xlsx('open_states_contested_votes.xlsx')

open_states_contested_votes_state = read_xlsx('open_states_contested_votes_state.xlsx')

shor = read_xlsx('shor_cleaned.xlsx')

################################## Alternative specifications for Table 2 ######################

### Table A1 -- pooled data

tA1_m1 = feols(data = bill_data,
              fml = as.formula(party_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score |Year + region),
              cluster = "State") %>% summary()

tA1_m2 = feols(data = bill_data,
              fml = as.formula(party_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score |Year + region),
              cluster = "State") %>% summary()

tA1_m3 = feols(data = bill_data,
              fml = as.formula(party_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score |Year + region),
              cluster = "State")

etable(tA1_m1, tA1_m2, tA1_m3)

### Table A2 -- bill-level controls

tA2_m1 = feols(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(party_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score + Amount_adj + Budget + Policy + Reform + IncomeWealth + SalesPurchases + GasVehicle + Sin + Business + Healthcare + OtherGovt |Year + region),
              cluster = "State") %>% summary()

tA2_m2 = feols(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(party_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score + Amount_adj + Budget + Policy + Reform + IncomeWealth + SalesPurchases + GasVehicle + Sin + Business + Healthcare + OtherGovt |Year + region),
              cluster = "State") %>% summary()

tA2_m3 = feols(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(party_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score + Amount_adj + Budget + Policy + Reform + IncomeWealth + SalesPurchases + GasVehicle + Sin + Business + Healthcare + OtherGovt|Year + region),
              cluster = "State")

tA2_m4 = feols(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(party_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score + Amount_adj + Budget + Policy + Reform + IncomeWealth + SalesPurchases + GasVehicle + Sin + Business + Healthcare + OtherGovt|Year + region),
              cluster = "State")

tA2_m5 = feols(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(party_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score + Amount_adj + Budget + Policy + Reform + IncomeWealth + SalesPurchases + GasVehicle + Sin + Business + Healthcare + OtherGovt|Year + region),
              cluster = "State")

tA2_m6 = feols(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(party_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score + Amount_adj + Budget + Policy + Reform + IncomeWealth + SalesPurchases + GasVehicle + Sin + Business + Healthcare + OtherGovt|Year + region),
              cluster = "State")

etable(tA2_m1, tA2_m2, tA2_m3, tA2_m4, tA2_m5, tA2_m6)

### Table A3 -- Logit models

tA3_m1 = feglm(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(party_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State",
              family = "binomial") %>% summary()

tA3_m2 = feglm(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(party_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State",
              family = "binomial") %>% summary()

tA3_m3 = feglm(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(party_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State",
              family = "binomial")

tA3_m4 = feglm(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(party_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State",
              family = "binomial")

tA3_m5 = feglm(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(party_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State",
              family = "binomial")

tA3_m6 = feglm(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(party_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State",
              family = "binomial")

etable(tA3_m1, tA3_m2, tA3_m3, tA3_m4, tA3_m5, tA3_m6)

### Figure A1 -- triple interaction from Table A3, Model 3

house = bill_data %>% filter(chamber == "House") %>% mutate(Party = ifelse(democratic == 1, "Democratic", "Republican"),
                                                           Partisan_control = ifelse(unified == 1, "Unified", "Divided"),
                                                           Veto_proof = ifelse(no_min_needed_either_chamber == 1, "No SM veto", "SM veto"))

housemodel1 = glm(data = house, family = "binomial",
                  formula = party_90 ~ Partisan_control*Veto_proof*Party + polarization + majority_unity + minority_unity + budgetary_power_score)

theme_set(theme_minimal() +
            theme(plot.background = element_rect(fill = "white")))

plot_model(housemodel1, type = "int", title ="", axis.title = c("","Probability of 90% unity vote"),legend.title = "", colors = c("grey10", "grey70"))

### Table A4 -- recession years only

tA4_m1 = feols(data = bill_data %>% filter(chamber == "House") %>% filter(Year == 2001 |Year == 2002 |Year == 2003 |Year == 2004 |Year == 2008 |Year == 2009 |Year == 2010 |Year == 2020),
              fml = as.formula(party_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score |region),
              cluster = "State") %>% summary()

tA4_m2 = feols(data = bill_data %>% filter(chamber == "House") %>% filter(Year == 2001 |Year == 2002 |Year == 2003 |Year == 2004 |Year == 2008 |Year == 2009 |Year == 2010 |Year == 2020),
              fml = as.formula(party_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score |region),
              cluster = "State") %>% summary()

tA4_m3 = feols(data = bill_data %>% filter(chamber == "House") %>% filter(Year == 2001 |Year == 2002 |Year == 2003 |Year == 2004 |Year == 2008 |Year == 2009 |Year == 2010 |Year == 2020),
              fml = as.formula(party_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score|region),
              cluster = "State")

tA4_m4 = feols(data = bill_data %>% filter(chamber == "Senate") %>% filter(Year == 2001 |Year == 2002 |Year == 2003 |Year == 2004 |Year == 2008 |Year == 2009 |Year == 2010 |Year == 2020),
              fml = as.formula(party_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score|region),
              cluster = "State")

tA4_m5 = feols(data = bill_data %>% filter(chamber == "Senate") %>% filter(Year == 2001 |Year == 2002 |Year == 2003 |Year == 2004 |Year == 2008 |Year == 2009 |Year == 2010 |Year == 2020),
              fml = as.formula(party_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score| region),
              cluster = "State")

tA4_m6 = feols(data = bill_data %>% filter(chamber == "Senate") %>% filter(Year == 2001 |Year == 2002 |Year == 2003 |Year == 2004 |Year == 2008 |Year == 2009 |Year == 2010 |Year == 2020),
              fml = as.formula(party_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score|region),
              cluster = "State")

etable(tA4_m1, tA4_m2, tA4_m3, tA4_m4, tA4_m5, tA4_m6)

### Table A5 -- include majority party size variable

tA5_m1 = feols(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(party_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score + majority_size_perc |Year + region),
              cluster = "State") %>% summary()

tA5_m2 = feols(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(party_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score + majority_size_perc |Year + region),
              cluster = "State") %>% summary()

tA5_m3 = feols(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(party_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score + majority_size_perc|Year + region),
              cluster = "State")

tA5_m4 = feols(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(party_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score + majority_size_perc|Year + region),
              cluster = "State")

tA5_m5 = feols(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(party_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score + majority_size_perc|Year + region),
              cluster = "State")

tA5_m6 = feols(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(party_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score + majority_size_perc|Year + region),
              cluster = "State")

etable(tA5_m1, tA5_m2, tA5_m3, tA5_m4, tA5_m5, tA5_m6)

### Table A6 -- Supermajority states only

tA6_m1 = feols(data = bill_data %>% filter(chamber == "House") %>% filter(SM == 1),
              fml = as.formula(party_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State") %>% summary()

tA6_m2 = feols(data = bill_data %>% filter(chamber == "House") %>% filter(SM == 1),
              fml = as.formula(party_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State") %>% summary()

tA6_m3 = feols(data = bill_data %>% filter(chamber == "House") %>% filter(SM == 1),
              fml = as.formula(party_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State")

tA6_m4 = feols(data = bill_data %>% filter(chamber == "Senate") %>% filter(SM == 1),
              fml = as.formula(party_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State")

tA6_m5 = feols(data = bill_data %>% filter(chamber == "Senate") %>% filter(SM == 1),
              fml = as.formula(party_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State")

tA6_m6 = feols(data = bill_data %>% filter(chamber == "Senate") %>% filter(SM == 1),
              fml = as.formula(party_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score),
              cluster = "State")

etable(tA6_m1, tA6_m2, tA6_m3, tA6_m4, tA6_m5, tA6_m6)

################################## Alternative dependent variables for Figures 2-3 and Table 2 ######################

Houses = bill_data %>% filter(chamber == "House")
Senates = bill_data %>% filter(chamber == "Senate")
House_R = bill_data %>% filter(chamber == "House" & majority == "R")
Senate_R = bill_data %>% filter(chamber == "Senate" & majority == "R")
House_D_divided = bill_data %>% filter(chamber == "House" & majority == "D" & unified == 0)
Senate_D_divided = bill_data %>% filter(chamber == "Senate" & majority == "D" & unified == 0)
House_D_unified_veto = bill_data %>% filter(chamber == "House" & majority == "D" & unified == 1 & min_needed_one_chamber == 1)
Senate_D_unified_veto = bill_data %>% filter(chamber == "Senate" & majority == "D" & unified == 1 & min_needed_one_chamber == 1)
House_D_unified_no_veto = bill_data %>% filter(chamber == "House" & majority == "D" & unified == 1 & min_needed_one_chamber == 0)
Senate_D_unified_no_veto = bill_data %>% filter(chamber == "Senate" & majority == "D" & unified == 1 & min_needed_one_chamber == 0)

### Figure A2 -- 90% minority party opposition votes in Figure 2

mean(Houses$minority_90)
mean(Senates$minority_90)
mean(House_R$minority_90)
mean(Senate_R$minority_90)
mean(House_D_divided$minority_90)
mean(Senate_D_divided$minority_90)
mean(House_D_unified_veto$minority_90)
mean(Senate_D_unified_veto$minority_90)
mean(House_D_unified_no_veto$minority_90)
mean(Senate_D_unified_no_veto$minority_90)

ggplot(data = descriptive_data, aes (x = minority_less_10_perc, y = chamber)) + 
  geom_bar(stat = "identity", position = "dodge") +
  theme_minimal() + labs (x = "90% minority opposition votes (%)", y = "") +
  xlim(0,100) + guides(fill = "none") + facet_wrap(~group)  +
  geom_text(aes(label = sample), vjust = 0.5, hjust = -0.1, color = "black")

### Figure A3 -- 50% party unity votes in Figure 2

mean(Houses$party_50)
mean(Senates$party_50)
mean(House_R$party_50)
mean(Senate_R$party_50)
mean(House_D_divided$party_50)
mean(Senate_D_divided$party_50)
mean(House_D_unified_veto$party_50)
mean(Senate_D_unified_veto$party_50)
mean(House_D_unified_no_veto$party_50)
mean(Senate_D_unified_no_veto$party_50)

ggplot(data = descriptive_data, aes (x = party_unity_50_perc, y = chamber)) + 
  geom_bar(stat = "identity", position = "dodge") +
  theme_minimal() + labs (x = "50% party unity votes (%)", y = "") +
  xlim(0,100) + guides(fill = "none") + facet_wrap(~group)  +
  geom_text(aes(label = sample), vjust = 0.5, hjust = -0.1, color = "black")

### Table A7 -- 90% minority opposition votes in Table 2

tA7_m1 = feols(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(minority_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score |Year + region),
              cluster = "State") %>% summary()

tA7_m2 = feols(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(minority_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score |Year + region),
              cluster = "State") %>% summary()

tA7_m3 = feols(data = bill_data %>% filter(chamber == "House"),
              fml = as.formula(minority_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score|Year + region),
              cluster = "State")

tA7_m4 = feols(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(minority_90 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score|Year + region),
              cluster = "State")

tA7_m5 = feols(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(minority_90 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score|Year + region),
              cluster = "State")

tA7_m6 = feols(data = bill_data %>% filter(chamber == "Senate"),
              fml = as.formula(minority_90 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score|Year + region),
              cluster = "State")

etable(tA7_m1, tA7_m2, tA7_m3, tA7_m4, tA7_m5, tA7_m6)

### Figure A4 -- 90% minority opposition votes in Figure 3

housemodel2 = lm(data = house,
                  formula = minority_90 ~ Partisan_control*Veto_proof*Party + polarization + majority_unity + minority_unity + budgetary_power_score)

theme_set(theme_minimal() +
            theme(plot.background = element_rect(fill = "white")))

plot_model(housemodel2, type = "int", title ="", axis.title = c("","Probability of 90% minority opposition vote"),legend.title = "", colors = c("grey10", "grey70"))

### Table A8 -- 50% party unity votes in Table 2

tA8_m1 = feols(data = bill_data %>% filter(chamber == "House"),
               fml = as.formula(party_50 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score |Year + region),
               cluster = "State") %>% summary()

tA8_m2 = feols(data = bill_data %>% filter(chamber == "House"),
               fml = as.formula(party_50 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score |Year + region),
               cluster = "State") %>% summary()

tA8_m3 = feols(data = bill_data %>% filter(chamber == "House"),
               fml = as.formula(party_50 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score|Year + region),
               cluster = "State")

tA8_m4 = feols(data = bill_data %>% filter(chamber == "Senate"),
               fml = as.formula(party_50 ~ democratic + polarization + majority_unity + minority_unity + budgetary_power_score|Year + region),
               cluster = "State")

tA8_m5 = feols(data = bill_data %>% filter(chamber == "Senate"),
               fml = as.formula(party_50 ~ democratic * unified + polarization + majority_unity + minority_unity + budgetary_power_score|Year + region),
               cluster = "State")

tA8_m6 = feols(data = bill_data %>% filter(chamber == "Senate"),
               fml = as.formula(party_50 ~ democratic * unified * no_min_needed_either_chamber + polarization + majority_unity + minority_unity + budgetary_power_score|Year + region),
               cluster = "State")

etable(tA8_m1, tA8_m2, tA8_m3, tA8_m4, tA8_m5, tA8_m6)

### Figure A5 -- 50% party unity votes in Figure 3

housemodel3 = lm(data = house,
                  formula = party_50 ~ Partisan_control*Veto_proof*Party + polarization + majority_unity + minority_unity + budgetary_power_score)

theme_set(theme_minimal() +
            theme(plot.background = element_rect(fill = "white")))

plot_model(housemodel3, type = "int", title ="", axis.title = c("","Probability of 50% unity vote"),legend.title = "", colors = c("grey10", "grey70"))

################################## Further information on tax increase bills ######################

### Figure A6-- tax increases by year

ggplot(data = bill_attr_year_data, aes(x = Year, y = n, fill = amount)) + 
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_gradient(low = "grey90", high = "grey10") +
  theme_minimal() + labs(fill = "Adjusted revenue raised", x="", y = "Tax increases passed")

### Figure A7 -- tax increases by state

ggplot(data = bill_attr_state_data, aes(x = State, y = n, fill = amount)) + 
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_gradient(low = "grey90", high = "grey10") +
  theme_minimal() + labs(fill = "Adjusted revenue raised", x="", y = "Tax increases passed") +
  theme(axis.text = element_text(angle = 90))

### Tax increases by type

ggplot(data = bill_attr_type_data, aes(x = Type, y = n, fill = amount)) + 
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_gradient(low = "grey90", high = "grey10") +
  theme_minimal() + labs(fill = "Adjusted revenue raised", x="", y = "Tax increases passed") +
  theme(axis.text = element_text(angle = 90))

### Table A9 -- amount of adjusted revenue

amount_1 = feols(data = bill_attr_data,
                 fml = as.formula(Amount_adj ~ Democratic| region + Year),
                 cluster = "State")

amount_2 = feols(data = bill_attr_data %>% filter(Democratic == "Dem"),
                 fml = as.formula(Amount_adj ~ Unified| region + Year),
                 cluster = "State")

amount_3 = feols(data = bill_attr_data %>% filter(Democratic == "Dem" & Unified == "Unified"),
                 fml = as.formula(Amount_adj ~ SM_rule| region + Year),
                 cluster = "State")

etable(amount_1, amount_2, amount_3)

### Table A10 -- included in budget bill

budget_1 = feols(data = bill_attr_data,
                 fml = as.formula(Budget ~ Democratic| region + Year),
                 cluster = "State")

budget_2 = feols(data = bill_attr_data %>% filter(Democratic == "Dem"),
                 fml = as.formula(Budget ~ Unified| region + Year),
                 cluster = "State")

budget_3 = feols(data = bill_attr_data %>% filter(Democratic == "Dem" & Unified == "Unified"),
                 fml = as.formula(Budget ~ SM_rule| region + Year),
                 cluster = "State")

etable(budget_1, budget_2, budget_3)

### Table A11 -- included tax cuts

reform_1 = feols(data = bill_attr_data,
                 fml = as.formula(Reform ~ Democratic| region + Year),
                 cluster = "State")

reform_2 = feols(data = bill_attr_data %>% filter(Democratic == "Dem"),
                 fml = as.formula(Reform ~ Unified| region + Year),
                 cluster = "State")

reform_3 = feols(data = bill_attr_data %>% filter(Democratic == "Dem" & Unified == "Unified"),
                 fml = as.formula(Reform ~ SM_rule| region + Year),
                 cluster = "State")

etable(reform_1, reform_2, reform_3)

### Table A12 -- impacted income or wealth

income_1 = feols(data = bill_attr_data,
                 fml = as.formula(IncomeWealth ~ Democratic| region + Year),
                 cluster = "State")

income_2 = feols(data = bill_attr_data %>% filter(Democratic == "Dem"),
                 fml = as.formula(IncomeWealth ~ Unified| region + Year),
                 cluster = "State")

income_3 = feols(data = bill_attr_data %>% filter(Democratic == "Dem" & Unified == "Unified"),
                 fml = as.formula(IncomeWealth ~ SM_rule| region + Year),
                 cluster = "State")

etable(income_1, income_2, income_3)

### Table A13 -- impacted sales or purchases

sales_1 = feols(data = bill_attr_data,
                fml = as.formula(SalesPurchases ~ Democratic| region + Year),
                cluster = "State")

sales_2 = feols(data = bill_attr_data %>% filter(Democratic == "Dem"),
                fml = as.formula(SalesPurchases ~ Unified| region + Year),
                cluster = "State")

sales_3 = feols(data = bill_attr_data %>% filter(Democratic == "Dem" & Unified == "Unified"),
                fml = as.formula(SalesPurchases ~ SM_rule| region + Year),
                cluster = "State")

etable(sales_1, sales_2, sales_3)

### Table A14 -- impacted sin purchases (i.e. alcohol, tobacco, marijuana, gambling, etc.)

sin_1 = feols(data = bill_attr_data,
              fml = as.formula(Sin ~ Democratic| region + Year),
              cluster = "State")

sin_2 = feols(data = bill_attr_data %>% filter(Democratic == "Dem"),
              fml = as.formula(Sin ~ Unified| region + Year),
              cluster = "State")

sin_3 = feols(data = bill_attr_data %>% filter(Democratic == "Dem" & Unified == "Unified"),
              fml = as.formula(Sin ~ SM_rule| region + Year),
              cluster = "State")

etable(sin_1, sin_2, sin_3)

### Table A15 -- impacted businesses

business_1 = feols(data = bill_attr_data,
                   fml = as.formula(Business ~ Democratic| region + Year),
                   cluster = "State")

business_2 = feols(data = bill_attr_data %>% filter(Democratic == "Dem"),
                   fml = as.formula(Business ~ Unified| region + Year),
                   cluster = "State")

business_3 = feols(data = bill_attr_data %>% filter(Democratic == "Dem" & Unified == "Unified"),
                   fml = as.formula(Business ~ SM_rule| region + Year),
                   cluster = "State")

etable(business_1, business_2, business_3)

### Table A16 -- impacted gas or motor vehicles

gas_1 = feols(data = bill_attr_data,
              fml = as.formula(GasVehicle ~ Democratic| region + Year),
              cluster = "State")

gas_2 = feols(data = bill_attr_data %>% filter(Democratic == "Dem"),
              fml = as.formula(GasVehicle ~ Unified| region + Year),
              cluster = "State")

gas_3 = feols(data = bill_attr_data %>% filter(Democratic == "Dem" & Unified == "Unified"),
              fml = as.formula(GasVehicle ~ SM_rule| region + Year),
              cluster = "State")

etable(gas_1, gas_2, gas_3)

### Table A17 -- impacted healthcare companies

health_1 = feols(data = bill_attr_data,
                 fml = as.formula(Healthcare ~ Democratic| region + Year),
                 cluster = "State")

health_2 = feols(data = bill_attr_data %>% filter(Democratic == "Dem"),
                 fml = as.formula(Healthcare ~ Unified| region + Year),
                 cluster = "State")

health_3 = feols(data = bill_attr_data %>% filter(Democratic == "Dem" & Unified == "Unified"),
                 fml = as.formula(Healthcare ~ SM_rule| region + Year),
                 cluster = "State")

etable(health_1, health_2, health_3)

### Table A18 -- impacted government fees or other miscellaneous revenue streams

other_1 = feols(data = bill_attr_data,
                fml = as.formula(OtherGovt ~ Democratic| region + Year),
                cluster = "State")

other_2 = feols(data = bill_attr_data %>% filter(Democratic == "Dem"),
                fml = as.formula(OtherGovt ~ Unified| region + Year),
                cluster = "State")

other_3 = feols(data = bill_attr_data %>% filter(Democratic == "Dem" & Unified == "Unified"),
                fml = as.formula(OtherGovt ~ SM_rule| region + Year),
                cluster = "State")

etable(other_1, other_2, other_3)

################################## Comparing states ######################

### Table A19 -- Open States models

a = feols(data = open_states_all_votes,
          fml = as.formula(coalition_size ~ tax_sm_rule  +  democratic_maj  +  unified  +  chamber|period  +  region),
          cluster = "jurisdiction")

b = feols(data = open_states_all_votes_state,
          fml = as.formula(avg_coalition ~ tax_sm_rule  +  democratic_maj  +  unified  +  chamber|period  +  region))

c = feols(data = open_states_contested_votes,
          fml = as.formula(coalition_size ~ tax_sm_rule  +  democratic_maj  +  unified  +  chamber|period  +  region),
          cluster = "jurisdiction")

d = feols(data = open_states_contested_votes_state,
          fml = as.formula(avg_coalition ~ tax_sm_rule  +  democratic_maj  +  unified  +  chamber|period  +  region))

etable(a, b, c, d)

### Table A20 -- Shor-McCarty score tables

a = feols(data = shor %>% filter(party == "D"),
          fml = as.formula(np_score ~ SM_rule| senate1993  +  senate1994  +  senate1995  +  senate1996  +  senate1997  +  senate1998  +  senate1999  +  senate2000  +  senate2001  +  senate2002  +  senate2003  +  senate2004  +  senate2005  +  senate2006  +  senate2007  +  senate2008  +  senate2009  +  senate2010 + senate2011 + senate2012 + senate2013 + senate2014 + senate2015 + senate2016 + senate2017 + senate2018 + senate2019 + senate2020 + house1993 + house1994 + house1995 + house1996 + house1997 + house1998 + house1999 + house2000 + house2001 + house2002 + house2003 + house2004 + house2005 + house2006 + house2007 + house2008 + house2009 + house2010 + house2011 + house2012 + house2013 + house2014 + house2015 + house2016 + house2017 + house2018 + house2019 + house2020),cluster = "st")
b = feols(data = shor %>% filter(party == "R"),
          fml = as.formula(np_score ~ SM_rule| senate1993  +  senate1994  +  senate1995  +  senate1996  +  senate1997  +  senate1998  +  senate1999  +  senate2000  +  senate2001  +  senate2002  +  senate2003  +  senate2004  +  senate2005  +  senate2006  +  senate2007  +  senate2008  +  senate2009  +  senate2010 + senate2011 + senate2012 + senate2013 + senate2014 + senate2015 + senate2016 + senate2017 + senate2018 + senate2019 + senate2020 + house1993 + house1994 + house1995 + house1996 + house1997 + house1998 + house1999 + house2000 + house2001 + house2002 + house2003 + house2004 + house2005 + house2006 + house2007 + house2008 + house2009 + house2010 + house2011 + house2012 + house2013 + house2014 + house2015 + house2016 + house2017 + house2018 + house2019 + house2020),cluster = "st")

etable(a,b)